<template>
	<view>
		<nav-bar :bgColor="['#4A67D6','#4A67D6']" fontColor="#FFFFFF" title="测试绑卡"></nav-bar>
		<!-- <button style="margin-top: 100rpx;" @tap="get_gb">打开监听</button> -->
		<view>{{rfid}}</view>
	</view>
</template>

<script>
	var main = null;
	var receiver = null;
	export default {
		data() {
			return {
				rfid: ''
			}
		},
		onLoad() {
			console.log("onLoad");
			this.get_gb();
		},
		onShow() {

		},
		onBackPress() {
			main.unregisterReceiver(receiver)
		},
		methods: {
			get_gb() {
				console.log()
				var that = this;
				main = plus.android.runtimeMainActivity();
				receiver = plus.android.implements('io.dcloud.android.content.BroadcastReceiver', {
					onReceive: function(context, intent) {
						plus.android.importClass(intent);
						var data = intent.getExtra("data");
						if (data) {
							that.rfid = data
							console.log('&&&' + that.rfid)
						}
					}
				});
				var IntentFilter = plus.android.importClass('android.content.IntentFilter');
				let filter = new IntentFilter();
				filter.addAction('android.rfid.epccode');
				var info = main.registerReceiver(receiver, filter)
				// main.unregisterReceiver(receiver)
			}
		}
	}
</script>

<style>

</style>
